package cn.tedu.supermarket.mapper;

import cn.tedu.supermarket.entity.OrdersDTO;
import cn.tedu.supermarket.entity.OrdersVO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface OrdersMapper {
    //添加订单
    @Insert("insert into orders values(null,#{userId},#{addressId},#{goodsId},#{price},#{num},#{sumPrice},#{status})")
    Integer insertInfo(OrdersVO ordersVO);
    //删除订单
    @Delete("delete from cart where id=#{id}")
    Integer deleteById(int id);
    //添加订单时用于补全信息
    @Select("select goodsId,num,sumPrice from cart where id=#{cartId}")
    OrdersVO selectBycartId(int cartId);
    @Select("select price from goods where id=#{goodsId}")
    Integer selectPriceByCartId(int goodsId);
    //将订单信息显示到页面
    @Select("select orders.id,orders.goodsId,goods.imgurl,goods.name,goods.price,orders.num,orders.sumPrice,orders.status,orders.addressId from orders left join goods on orders.goodsId=goods.id where userId=#{userId}")
    List<OrdersDTO> selectByUserId(int userId);
    //查询addressId
    @Select("select distinct addressId from orders where userId=#{userId}")
    int[] selectAddressIdByUserId(int userId);
    //确认收货
    @Update("update orders set status='已收货' where id=#{id}")
    Integer updateStatusById(int id);
    //显示未发货,已发货,已收货订单
    @Select("select orders.id,orders.goodsId,goods.imgurl,goods.name,goods.price,orders.num,orders.sumPrice,orders.status,orders.addressId from orders left join goods on orders.goodsId=goods.id where userId=#{userId} and status=#{status}")
    List<OrdersDTO> selectByStatus(@Param("userId") int userId,@Param("status")String status);

    //商家已发货
    @Update("update orders set status='已发货' where id=#{id}")
    Integer updateStatus(int id);
}
